<?php
namespace Home\Controller;
use Think\Controller;
include 'phpQuery/phpQuery.php';
header("Content-Type:text/html;charset=utf-8");
class IndexController extends Controller {
    public function index()
    {
        //一下是验证Token,其实并不需要
//         $timestamp =$_GET['timestamp'];
//         $nonce     =$_GET['nonce'];
//         $token     ='weixin';
//         $signature =$_GET['signature'];
//         $echostr   =$_GET['echostr'];
//         $array = array($timestamp, $nonce, $token);
//         sort($array);
// //2、将排序后的三个参数拼接之后用sha1加密
//         $tmpstr = implode('', $array);
//         $tmpstr = sha1($tmpstr);
// //3、将加密后的字符串与signature进行对比，判断该请求是否来自微信
//         if ($tmpstr == $signature&&$echostr) {
//             //第一次接入微信api接口的时候
//             echo $_GET['echostr'];
//             exit;
//         }else{

            /**
             * 正式运作只运行这一行
             */
            $this->responseMsg();
            /**
             * 调试
             */
          //  $postObj->Content = '知乎';
          //  $this->responseMsg();
        // }
    }

    // public function index_responseMsg(){
    //     $this->responseMsg();
    // }


    //接受事件推送并回复消息
    public function responseMsg(){
        //获取微信推送过来的post数据（xml数据）php://input
        $postArr=file_get_contents("php://input");
        //知乎操作破案段变量
        $ZhihuJudge = 0;
        /*
        <xml>
             <ToUserName><![CDATA[toUser]]></ToUserName>
             <FromUserName><![CDATA[fromUser]]></FromUserName>
             <CreateTime>1348831860</CreateTime>
             <MsgType><![CDATA[text]]></MsgType>
             <Content><![CDATA[this is a test]]></Content>
             <MsgId>1234567890123456</MsgId>
        </xml>
        */
        //处理消息类型并设置回复的消息内容和类型
        $postObj=simplexml_load_string($postArr);

        var_dump('</br></br>URL=>'.strtolower($postObj->URL));
        var_dump('</br></br>ToUserName=>'.strtolower($postObj->ToUserName));
        var_dump('</br></br>FromUserName=>'.strtolower($postObj->FromUserName));
        var_dump('</br></br>CreateTime=>'.strtolower($postObj->CreateTime));
        var_dump('</br></br>Content=>'.strtolower($postObj->Content));
        var_dump('</br></br>MsgId=>'.strtolower($postObj->MsgId));

        var_dump('</br></br>MsgType=>'.strtolower($postObj->MsgType));
        var_dump('</br></br>Event=>'.strtolower($postObj->Event));



        //判断该数据包是不是订阅的事件推送
        if(strtolower($postObj->MsgType)=='event'){
            var_dump('</br></br>订阅推送</br></br>');
            //如果是关注subscribe
            // if(strtolower($postObj->Event)=='heeh4zd'){
                //回复用户消息
                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $time    =time();
                $msgType ='text';
                $content ='欢迎关注公众号 修的PHP ！
这是我自己用ThinkPHP3.2自学写的公众号!
欢迎浏览我的文章与我推荐的大牛文章!
请回复 "菜单" 来使用本公众号!
祝您生活愉快!';
                $template="
                            <xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info=sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
                // var_dump($info);
                echo  $info;

            // }
        }
        //纯文本回复消息
        if(strtolower($postObj->MsgType=='text')){
            /**
             *每写一句,要把这歌判断数组里加一个,要不不好使
             */
            $func = array('菜单','历史','关于','推荐','天气','商城','博客','知乎');
            $input = $postObj->Content;

            if(!in_array($input,$func) && !$ZhihuJudge){
                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $time    =time();
                $msgType ='text';
                $content ='不管您有什么要求,请回复 "菜单" 查看本公众号的所有功能!';   //可以写成一个超链接$content="<a href="www.baidu.com">百度</a>";
                $template="
                            <xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info=sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
                var_dump('</br></br>$info=>',$info);
                echo  $info;
            }

            if($postObj->Content=='菜单' && !$ZhihuJudge){
                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $time    =time();
                $msgType ='text';
                $content ='这里是修的PHP--菜单!  回复:
"天气" --查看天气预报!
"商城" --查看个人商城项目!
"博客" --查看个人博客!
"推荐" --查看大牛文章!
"知乎" --查看PHP知乎头条!
"历史" --查看历史文章!(敬请期待)
"关于" --查看个人资料!(敬请期待)';   //可以写成一个超链接$content="<a href="www.baidu.com">百度</a>";
                $template="
                            <xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info=sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
                var_dump('</br></br>$info=>',$info);
                echo  $info;
            }

            //推荐
            if(strtolower($postObj->MsgType=='text') && strtolower($postObj->Content=='推荐')){
                var_dump('</br></br>tuwen1关键字</br></br>');

                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $arr=array(
                    array(
                    'title'=>'老霍写的关于 "永恒之蓝" ',
                    'description'=>'做一个病毒卷土重来时代的幸存者',
                    'picUrl'=>'http://119.29.160.15/serverpic/WanaDecryptor_bak.png',
                    'url'=>'https://mp.weixin.qq.com/s/_5MP-mq_AttVlw1tj7zI9A'
                    ),
                );
                $template="<xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <ArticleCount>".count($arr)."</ArticleCount>
                                <Articles>";
                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title']."]]></Title>
                                <Description><![CDATA[".$v['description']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl>
                                <Url><![CDATA[".$v['url']."]]></Url>
                                </item>";
                                }
                      $template.="</Articles>
                             </xml>";
                $info=sprintf($template,$toUser,$fromUser,time(),'news');
                echo  $info;
            }

            //天气
            if(strtolower($postObj->MsgType=='text') && strtolower($postObj->Content=='天气')){
              $wea = $this->Weather();
              $toUser=$postObj->FromUserName;
              $fromUser=$postObj->ToUserName;

              $nowWeather = $wea['country'].'-'.$wea['province'].'-'.$wea['city'].'
当前天气：'.$wea['now']['weather'].' '.$wea['now']['temperature'].'度'.'  '.$wea['now']['wind_direction'].'：'.$wea['now']['wind_power'].' '.'空气湿度：'.$wea['now']['sd'];


              $nowTemplate = "
                  <xml>

                  <ToUserName><![CDATA[%s]]></ToUserName>

                  <FromUserName><![CDATA[%s]]></FromUserName>

                  <CreateTime>%s</CreateTime>

                  <MsgType><![CDATA[%s]]></MsgType>

                  <Content><![CDATA[%s]]></Content>

                  </xml>
              ";

              $Img = "
                  <xml>
                  <ToUserName><![CDATA[%s]]></ToUserName>
                  <FromUserName><![CDATA[%s]]></FromUserName>
                  <CreateTime>%s</CreateTime>
                  <MsgType><![CDATA[%s]]></MsgType>
                  <ArticleCount>3</ArticleCount>
                  <Articles>
                  <item>
                  <Title><![CDATA[当前天气]]></Title>
                  <Description><![CDATA[".$wea['now']['weather']."]]></Description>
                  <PicUrl><![CDATA[".$wea['now']['weather_pic']."]]></PicUrl>
                  <Url><![CDATA[http://119.29.160.15/chinatianqi_api/]]></Url>
                  </item>
                  <item>
                  <Title><![CDATA[今天白天]]></Title>
                  <Description><![CDATA[".$wea['today']['day_weather']."]]></Description>
                  <PicUrl><![CDATA[".$wea['today']['day_weather_pic']."]]></PicUrl>
                  <Url><![CDATA[http://119.29.160.15/chinatianqi_api/]]></Url>
                  </item>
                  <item>
                  <Title><![CDATA[今天夜间]]></Title>
                  <Description><![CDATA[".$wea['today']['night_weather']."]]></Description>
                  <PicUrl><![CDATA[".$wea['today']['night_weather_pic']."]]></PicUrl>
                  <Url><![CDATA[http://119.29.160.15/chinatianqi_api/]]></Url>
                  </item>
                  </Articles>
                  </xml>
              ";

              $imgInfo = sprintf($Img,$toUser,$fromUser,time(),'news');
              $nowInfo = sprintf($nowTemplate,$toUser,$fromUser,time(),'text',$nowWeather);

              echo $imgInfo;
              echo $nowInfo;

            }

            if(strtolower($postObj->MsgType=='text') && strtolower($postObj->Content=='商城')){

                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $arr=array(
                    array(
                    'title'=>'仿小米商城',
                    'description'=>'Tp3.2制作',
                    'picUrl'=>'http://119.29.160.15/internship_tp/shopping.png',
                    'url'=>'http://119.29.160.15/internship_tp/',
                    'title1'=>'商城后台',
                    'description1'=>'Tp3.2制作',
                    'picUrl1'=>'http://119.29.160.15/internship_tp/admin.png',
                    'url1'=>'http://119.29.160.15/internship_tp/admin',
                    ),
                );
                $template="<xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <ArticleCount>2</ArticleCount>
                                <Articles>";
                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title']."]]></Title>
                                <Description><![CDATA[".$v['description']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl>
                                <Url><![CDATA[".$v['url']."]]></Url>
                                </item>";
                                }

                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title1']."]]></Title>
                                <Description><![CDATA[".$v['description1']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl1']."]]></PicUrl>
                                <Url><![CDATA[".$v['url1']."]]></Url>
                                </item>";
                                }
                      $template.="</Articles>
                             </xml>";
                $info=sprintf($template,$toUser,$fromUser,time(),'news');
                echo  $info;
            }

            if(strtolower($postObj->MsgType=='text') && strtolower($postObj->Content=='博客')){

                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $arr=array(
                    array(
                    'title'=>'脩の博客',
                    'description'=>'Php7.0原生制作',
                    'picUrl'=>'http://119.29.160.15/internship_native/Home.png',
                    'url'=>'http://119.29.160.15/internship_native/',
                    'title1'=>'博客后台',
                    'description1'=>'Php7.0原生制作',
                    'picUrl1'=>'http://119.29.160.15/internship_native/Admin.png',
                    'url1'=>'http://119.29.160.15/internship_native/Admin',
                    ),
                );
                $template="<xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <ArticleCount>2</ArticleCount>
                                <Articles>";
                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title']."]]></Title>
                                <Description><![CDATA[".$v['description']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl>
                                <Url><![CDATA[".$v['url']."]]></Url>
                                </item>";
                                }

                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title1']."]]></Title>
                                <Description><![CDATA[".$v['description1']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl1']."]]></PicUrl>
                                <Url><![CDATA[".$v['url1']."]]></Url>
                                </item>";
                                }
                      $template.="</Articles>
                             </xml>";
                $info=sprintf($template,$toUser,$fromUser,time(),'news');
                echo  $info;
            }
            //触发知乎
            if($postObj->Content=='知乎'){
                $ZhihuJudge = 1;
                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $time    =time();
                $msgType ='text';
                $content ='修宇知乎--请输入您要的知乎版块(专栏)';   //可以写成一个超链接$content="<a href="www.baidu.com">百度</a>";
                $template="
                            <xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info=sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
                echo  $info;
            }
            //知乎前十条
            /**
             * 处理知乎任意版块
             */
            $Zhihu = explode('-',$postObj->Content);
            if(strtolower($postObj->MsgType=='text') && $ZhihuJudge==1){
                $ZhihuJudge = 0;
                $crawler = $this->crawler();
                $toUser=$postObj->FromUserName;
                $fromUser=$postObj->ToUserName;
                $arr=array(
                    array(
                    'title'=>$crawler['title']['0'],
                    'description'=>"切换专栏请重新输入'知乎'",
                    'picUrl'=>'http://119.29.160.15/wx/zhihu.png',
                    'url'=>'http://119.29.160.15/wx/index.php?c=Zhihu&a=index',
                    ),
                );
                $template="<xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <ArticleCount>1</ArticleCount>
                                <Articles>";
                                foreach($arr as $k=>$v){
                     $template.="<item>
                                <Title><![CDATA[".$v['title']."]]></Title>
                                <Description><![CDATA[".$v['description']."]]></Description>
                                <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl>
                                <Url><![CDATA[".$v['url']."]]></Url>
                                </item>";
                                }
                      $template.="</Articles>
                             </xml>";
                $info=sprintf($template,$toUser,$fromUser,time(),'news');
                echo  $info;
            }
        }


    }


   public function crawler(){
       /**
        * 官网 http://code.google.com/p/phpquery/
        * 爬知乎PHP专栏每条帖子(后期输入专栏爬)<前十条>
        */

       \phpQuery::newDocumentFile('https://www.zhihu.com/search?type=content&q=php');
       $artlist = pq(".title");
       $praise = pq(".zm-item-vote-count");
       $author = pq(".author-line");
       $abstract = pq(".bio");
       $content = pq(".zm-item-vote-info");

       //不知为何要严格定义这个数组,否则无法赋值
       $data = array();
       foreach($artlist as $k=>$li){
         $data['title']["$k"] = pq($li)->html();
       }
       $even = 0;
       foreach ($praise as $k => $v) {
         if ($k%2!=0) {
           continue;
         }
         $data['praise']["$even"] = pq($v)->html();
         $even++;
       }

       foreach ($author as $k => $v) {
         if (pq($v)->html() == '匿名用户') {
           $data['author']["$k"] = '匿名用户';
         }else{
           $data['author']["$k"] = pq($v)->find('span')->find('a')->html();
         }
         // $data['author']["$k"] = pq($v)->html();
       }

       foreach ($abstract as $k => $v) {
         $data['abstract']["$k"] = pq($v)->html();
       }

       foreach ($content as $k => $v) {
         $data['content']["$k"] = pq($v)->next()->html();
       }
       /**
        * 测试输出
        */
      //  p($data);

      return $data;

       /**
        * 解析XML文档
        */
       // include 'phpQuery/phpQuery.php';
       // phpQuery::newDocumentFile('test.xml');
       // echo pq('contact > age:eq(0)');
   }

   public function Weather(){
     $host = "https://ali-weather.showapi.com";
     $path = "/ip-to-weather";
     $method = "GET";
     $appcode = "1828fefd3a40452d98bc47de5daf30e1";
     $headers = array();
     array_push($headers, "Authorization:APPCODE " . $appcode);
     $querys = "ip=202.98.20.177&need3HourForcast=0&needAlarm=1&needHourData=0&needIndex=1&needMoreDay=1";
     $bodys = "";
     $url = $host . $path . "?" . $querys;

     $curl = curl_init();
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_FAILONERROR, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HEADER, true);
     if (1 == strpos("$".$host, "https://"))
     {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     }

     // var_dump(curl_exec($curl));

     // $json = curl_exec($curl);
     // var_dump($json);

     // $exp = explode("{",$json);
     // p($exp);

     // $arr = json_decode($json,true);
     // var_dump($arr);
     $json = curl_exec($curl);
     // var_dump($json);

     $all="{\"".$this->getNeedBetween($json, '"showapi_res_code"' , '}}}' )."}}}";
     // var_dump($all);
     $arr = json_decode($all,true);
     // p($arr);
     // die();

     $data = array(
         'time' => $arr['showapi_res_body']['time'], //预报发布时间
         'country' => $arr['showapi_res_body']['cityInfo']['c9'],
         'province' => $arr['showapi_res_body']['cityInfo']['c7'],
         'city' => $arr['showapi_res_body']['cityInfo']['c3'],
         //现在实时的天气情况
         'now' => array(
             'wind_direction' => $arr['showapi_res_body']['now']['wind_direction'],
             'wind_power' => $arr['showapi_res_body']['now']['wind_power'],
             'sd' => $arr['showapi_res_body']['now']['sd'], //空气湿度
             'weather_pic' => $arr['showapi_res_body']['now']['weather_pic'],//天气小图标
             'weather' => $arr['showapi_res_body']['now']['weather'], //天气
             'temperature' => $arr['showapi_res_body']['now']['temperature'],//气温
             ),
         'today' => array(
             'day' => $arr['showapi_res_body']['f1']['day'],//当前天
             'weekday' => $arr['showapi_res_body']['f1']['weekday'], //星期几
             'day_weather' => $arr['showapi_res_body']['f1']['day_weather'], //白天天气
             'day_weather_pic' => $arr['showapi_res_body']['f1']['day_weather_pic'],//白天天气图标
             'day_air_temperature' => $arr['showapi_res_body']['f1']['day_air_temperature'],//白天天气温度(摄氏度)
             'night_weather' => $arr['showapi_res_body']['f1']['night_weather'],//晚上天气
             'night_weather_pic' => $arr['showapi_res_body']['f1']['night_weather_pic'],//晚上天气图标
             'night_air_temperature' =>  $arr['showapi_res_body']['f1']['night_air_temperature'], //晚上天气温度(摄氏度)
             'ls' => array(//晾晒指数
                 'title' => $arr['showapi_res_body']['f1']['index']['ls']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['ls']['desc'],
                 ),
             'clothes' => array(//穿衣指数
                 'title' => $arr['showapi_res_body']['f1']['index']['clothes']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['clothes']['desc'],
                 ),
             'beauty' => array(//化妆指数
                 'title' => $arr['showapi_res_body']['f1']['index']['beauty']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['beauty']['desc'],
                 ),
             'gj' => array(//逛街指数
                 'title' => $arr['showapi_res_body']['f1']['index']['gj']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['gj']['desc'],
                 ),
             'uv' => array(//紫外线
                 'title' => $arr['showapi_res_body']['f1']['index']['uv']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['uv']['desc'],
                 ),
             'aqi' => array(//空气质量指数，越小越好
                 'num' =>  $arr['showapi_res_body']['now']['aqi'],
                 'title' => $arr['showapi_res_body']['f1']['index']['aqi']['title'],
                 'desc' => $arr['showapi_res_body']['f1']['index']['aqi']['desc'],
                 ),
             'jiangshui' => $arr['showapi_res_body']['f1']['jiangshui'],//降水概率
             ),
         'tomorrow' => array(
             //同today
             'day' => $arr['showapi_res_body']['f2']['day'],//当前天
             'weekday' => $arr['showapi_res_body']['f2']['weekday'], //星期几
             'day_weather' => $arr['showapi_res_body']['f2']['day_weather'], //白天天气
             'day_weather_pic' => $arr['showapi_res_body']['f2']['day_weather_pic'],//白天天气图标
             'day_air_temperature' => $arr['showapi_res_body']['f2']['day_air_temperature'],//白天天气温度(摄氏度)
             'night_weather' => $arr['showapi_res_body']['f2']['night_weather'],//晚上天气
             'night_weather_pic' => $arr['showapi_res_body']['f2']['night_weather_pic'],//晚上天气图标
             'night_air_temperature' =>  $arr['showapi_res_body']['f2']['night_air_temperature'], //晚上天气温度(摄氏度)
             'ls' => array(//晾晒指数
                 'title' => $arr['showapi_res_body']['f2']['index']['ls']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['ls']['desc'],
                 ),
             'clothes' => array(//穿衣指数
                 'title' => $arr['showapi_res_body']['f2']['index']['clothes']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['clothes']['desc'],
                 ),
             'beauty' => array(//化妆指数
                 'title' => $arr['showapi_res_body']['f2']['index']['beauty']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['beauty']['desc'],
                 ),
             'gj' => array(//逛街指数
                 'title' => $arr['showapi_res_body']['f2']['index']['gj']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['gj']['desc'],
                 ),
             'uv' => array(//紫外线
                 'title' => $arr['showapi_res_body']['f2']['index']['uv']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['uv']['desc'],
                 ),
             'aqi' => array(//空气质量指数，越小越好
                 'title' => $arr['showapi_res_body']['f2']['index']['aqi']['title'],
                 'desc' => $arr['showapi_res_body']['f2']['index']['aqi']['desc'],
                 ),
             'jiangshui' => $arr['showapi_res_body']['f2']['jiangshui'],//降水概率
             ),
         );

     /**
      * 总输出
      */
     // p($data);
     return $data;
   }

   function p($data){
       echo '<pre>';
       print_r($data);
       echo '</pre>';
   }

   function getNeedBetween($kw1,$mark1,$mark2){
       $kw=$kw1;
       $st =stripos($kw,$mark1);
       $ed =stripos($kw,$mark2);
       if(($st==false||$ed==false)||$st>=$ed)
       return 0;
       $kw=substr($kw,($st+1),($ed-$st-1));
       return $kw;
   }


}
